// Brandon Evers + Zach Fedora	Circle.java		Final Project

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Point;
import java.util.Random;

import javax.swing.JPanel;


public class DrawCircles extends JPanel
{
	private Dimension size; //For Rexy
	private Point[] locs;
	private int[] circleSizes;
	private Color[] selectedColors;
	
	//Buys a car
	public DrawCircles(Dimension s, int i)
	{
		this.size = s;
		size.height -= 30;
		locs = new Point[i];
		circleSizes = new int[i];
		selectedColors = new Color[i];
		setRandLocs();
		setRandSizes();
		setRandColors();
		this.setVisible(true);
	}
	
	//Calls Jesus.
	public void drawCircles(Graphics g)
	{
		for(int a = 0; a < circleSizes.length; a++)
		{
			g.setColor(selectedColors[a]);
			g.drawOval(locs[a].x, locs[a].y, circleSizes[a], circleSizes[a]);
			g.fillOval(locs[a].x, locs[a].y, circleSizes[a], circleSizes[a]);
			//draw eyes
			g.setColor(Color.BLACK);
			g.drawOval(locs[a].x + circleSizes[a] / 3, locs[a].y + circleSizes[a] / 4, 5, 5);
			g.fillOval(locs[a].x + circleSizes[a] / 3, locs[a].y + circleSizes[a] / 4, 5, 5);
			g.drawOval(locs[a].x + circleSizes[a] - (circleSizes[a] / 2) , locs[a].y + circleSizes[a] / 4, 5, 5);
			g.fillOval(locs[a].x + circleSizes[a] - (circleSizes[a] / 2) , locs[a].y + circleSizes[a] / 4, 5, 5);
			int r = (int)(Math.random() * 75);
			if(r < 10)
				r += 25;
			g.drawArc(locs[a].x, locs[a].y - (circleSizes[a] / 3) , circleSizes[a], circleSizes[a], 245 , r);
			
		}
	}
	
	//Sets random locations according to width and height to array.
	public void setRandLocs()
	{
		boolean same = false;
		for(int a = 0; a < locs.length; a++)
		{
			int randX = (int) (Math.random() * size.width);
			if(randX > size.width * .8)
				randX -= 50;
			int randY = (int) (Math.random() * size.height);
			if(randY > size.height * .8)
				randY -= 50;
			for(int b = 0; b < a; b++)
			{
				if(locs[b].equals(new Point(randX, randY)))
				{
					a--;
					same = true;
					break;
				}
				else
					same = false;
			}
			if (same == false)
				locs[a] = new Point(randX, randY);
		}
	}
	
	//Sets random size according to our calculations and array.
	public void setRandSizes()
	{
		for(int a = 0; a < circleSizes.length; a++)
		{
			int randSize = (int)(Math.random() * 100);
			if(randSize < 25)
				randSize += 25;
			circleSizes[a] = randSize;
		}
	}
	
	//Set random colors from color array from a poll of 100 people calculated.
	public void setRandColors()
	{
		for(int a = 0; a < selectedColors.length; a++)
		{
			Random randomGenerator = new Random();
			int red = randomGenerator.nextInt(255);
			int green = randomGenerator.nextInt(255);
			int blue = randomGenerator.nextInt(255);
			Color randomColour = new Color(red,green,blue);
			selectedColors[a] = randomColour;
		}
	}
	
	//I have no clue what this does, but T-Rex wanted it in.
	public Dimension getPreferredSize()
	{
		return this.size;
	}
	
	//Magically puts circles on magic box thing.
	public void paint(Graphics g)
	{
		drawCircles(g);
	}
	
}
